<template>
  <view class="setting-container" :style="{height: `${windowHeight}px`}">
    <view class="menu-list">
      <view class="list-cell list-cell-arrow" @click="handleTolang">
        <view class="menu-item-box">
          <view class="iconfont icon-passingproicon- menu-icon"></view>
          <view>{{$t('mine.langChange')}}</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="goSeeSncode">
        <view class="menu-item-box">
          <view class="iconfont icon-shebeihao1 menu-icon"></view>
          <view>{{$t('mine.deviceNumber')}}</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="goClearScanInfo">
        <view class="menu-item-box">
          <view class="iconfont icon-qinglihuancun menu-icon"></view>
          <view>{{ $t('common.clear')+$t('common.scan')+$t('common.cache') }}</view>
        </view>
      </view>
      
    <!--  <view class="list-cell list-cell-arrow" @click="handleToPwd">
        <view class="menu-item-box">
          <view class="iconfont icon-password menu-icon"></view>
          <view>修改密码</view>
        </view>
      </view> 
	  <view class="list-cell list-cell-arrow" @click="handleToUpgrade">
        <view class="menu-item-box">
          <view class="iconfont icon-refresh menu-icon"></view>
          <view>检查更新</view>
        </view>
      </view>
      <view class="list-cell list-cell-arrow" @click="handleCleanTmp">
        <view class="menu-item-box">
          <view class="iconfont icon-clean menu-icon"></view>
          <view>清理缓存</view>
        </view>
      </view> -->
    </view>
    <view class="cu-list menu">
      <view class="cu-item item-box">
        <view class="content text-center" @click="handleLogout">
          <text class="text-black">{{ $t('common.signOut') }}</text>
        </view>
      </view>
    </view>
  </view>
</template>

<script>
  import { showConfirm,copyText } from '../../../utils/common'
  export default {
    data() {
      return {  
        windowHeight: uni.getSystemInfoSync().windowHeight,
      }
    },
    onLoad() {
      this.$nextTick(()=>{
        uni.setNavigationBarTitle({
          title: this.$t('common.app') + this.$t('common.set')
        });
      })
    },
    methods: {
      handleToPwd() {
        this.$tab.navigateTo('/pages/mine/pwd/index')
      },
      handleToUpgrade() {
        this.$modal.showToast(this.$t('common.develop')) 
      },
      handleCleanTmp() {
        this.$modal.showToast(this.$t('common.develop')) 
      },
      handleTolang(e){
        const langList = this.$i18n.getLangList()
        uni.showActionSheet({
          itemList: langList.map((item)=>item.label),
          success: (res) => {
            const locale = langList[res.tapIndex].value
            this.switchLanguage(locale); 
          }
        });
      },
      switchLanguage(locale) {
        console.log('locale',locale)
        this.$i18n.setLocale(locale);
        this.$nextTick(()=>{
          // this.$forceUpdate(); // 强制更新视图
          this.$tab.reLaunch('/pages/home/index',{
            complete:()=>{
              this.initTabs()
            }
          });
        })
      },
      initTabs(){
        uni.setTabBarItem({
          index:0,
          text:this.$t('home.home')
        })
        uni.setTabBarItem({
          index:1,
          text:this.$t('mine.my')
        })
      },
      goSeeSncode(){
        const sncode = this.$store.getters.sncode
        showConfirm(sncode,{
          title:this.$t('mine.deviceNumber'),
          confirmText:this.$t('common.copy'),
          cancelText:this.$t('common.cancel')
        }).then(res => {
          if (res.confirm) {
            copyText(sncode)
          }
        })
      },
      async goClearScanInfo(){
        await this.$store.dispatch('setScanCode',{ type:'allClear' })
        this.$modal.msgSuccess(this.$t('common.clear')+this.$t('common.success'))
      },
      handleLogout() {
          this.$modal.confirm(this.$t('common.sure')+this.$t('common.signOut')+'？').then(() => {
            this.$store.dispatch('LogOut').then(() => {
              this.$tab.reLaunch('/pages/login/login')
            })
          })
      }
    }
  }
</script>

<style lang="scss" scoped>
  .page {
    background-color: #f8f8f8;
  }

  .item-box {
    background-color: #FFFFFF;
    margin: 30rpx;
    display: flex;
    flex-direction: row;
    justify-content: center;
    align-items: center;
    padding: 10rpx;
    border-radius: 8rpx;
    color: #303133;
    font-size: 32rpx;
  }
</style>
